#ifndef BOX_H
#define BOX_H

#include <QString>
#include <QVector>
#include <QDateTime>

typedef struct
{
    QString name;
    QString desc;
    QDateTime dateTime;
    int count;
} BoxItemData;

typedef struct
{
    BoxItemData info;
    QVector<BoxItemData> sorts;
} BoxItem;

/**
 * @brief The Box class
 * Holds list of items, it's count,
 */
class Box
{
public:
    /**
     * @brief Box
     * empty box
     */
    Box();

    /**
     * @brief Box
     * @param str item1 [{description}] [[count]] ( sort1 [{description}] [[count]], sort2 [{description}] [[count]] ); ...
     * box from string
     */
    Box(const QString &str);

    /**
     * @brief boxName
     * @return name of box (e.g. it's id in db)
     */
    QString boxName() const;

    /**
     * @brief setBoxName
     * @param str
     */
    void setBoxName(const QString &newName);

    /**
     * @brief itemsTotal
     * @return items in this box
     */
    int itemsTotal() const;

    /**
     * @brief itemName
     * @param itemIdx
     * @return item name
     */
    QString itemName(int itemIdx) const;

    /**
     * @brief itemCount
     * @param itemIdx
     * @return number of this sort of item in box
     */
    int itemCount(int itemIdx) const;

    /**
     * @brief itemDesc
     * @param itemIdx
     * @return description of item
     */
    QString itemDesc(int itemIdx) const;

    /**
     * @brief itemDateTime
     * @param itemIdx
     * @return
     */
    QDateTime itemDateTime(int itemIdx) const;

private:
    void parse(const QString &str);
    void parseItem(const QString &str);
    void parseNameDescCountDate(const QString &str, BoxItemData &itemData);
    bool isValidIdx(int idx) const;
    QString m_boxName;
    QVector<BoxItem> m_items;

    static const QString m_rxText;
    static const QString m_rxNumber; // 123
    static const QRegExp m_rxName; // text
    static const QRegExp m_rxDesc; // {...}
    static const QRegExp m_rxDateTime; // <...>
    static const QRegExp m_rxCount; // [...]
    static const QRegExp m_rxSorts; // (...)
};

#endif // BOX_H
